'use strict';

const Service = require('egg').Service;

class TodoService extends Service {
  async findOne({ id }) {
    return await this.ctx.model.Todo.findById(id);
  }

  async create({ body }) {
    const todoModel = this.ctx.model.Todo;
    return await todoModel.create(body);
  }

  async remove({ id }) {
    const todoModel = this.ctx.model.Todo;
    return await todoModel.findByIdAndRemove(id);
  }

  async updateOne({ id, body }) {
    return await this.ctx.model.Todo.findByIdAndUpdate(id, {
      $set: body,
    });
  }
}

module.exports = TodoService;
